﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace WebAPI_Text.Models.Database
{
    public partial class mystoreContext : DbContext
    {
        public mystoreContext()
        {
        }

        public mystoreContext(DbContextOptions<mystoreContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Article> Articles { get; set; }
        public virtual DbSet<Car> Cars { get; set; }
        public virtual DbSet<Category> Categories { get; set; }
        public virtual DbSet<Good> Goods { get; set; }
        public virtual DbSet<Like> Likes { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=mystore;Integrated Security=SSPI");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Article>(entity =>
            {
                entity.HasKey(e => e.Aid);

                entity.ToTable("Article");

                entity.Property(e => e.Aid)
                    .ValueGeneratedNever()
                    .HasColumnName("AId");

                entity.Property(e => e.Abrowse).HasColumnName("ABrowse");

                entity.Property(e => e.AcateId).HasColumnName("ACateId");

                entity.Property(e => e.Acontent)
                    .HasColumnType("text")
                    .HasColumnName("AContent");

                entity.Property(e => e.Asource)
                    .HasMaxLength(50)
                    .HasColumnName("ASource");

                entity.Property(e => e.Atitle)
                    .HasMaxLength(50)
                    .HasColumnName("ATitle");

                entity.Property(e => e.PubTime).HasColumnType("datetime");
            });

            modelBuilder.Entity<Car>(entity =>
            {
                entity.HasKey(e => e.RecordId);

                entity.Property(e => e.CreateDate).HasColumnType("datetime");
            });

            modelBuilder.Entity<Category>(entity =>
            {
                entity.ToTable("Category");

                entity.Property(e => e.Id)
                    .ValueGeneratedNever()
                    .HasComment("主键");

                entity.Property(e => e.CateName)
                    .IsRequired()
                    .HasMaxLength(255)
                    .HasComment("分类名称");
            });

            modelBuilder.Entity<Good>(entity =>
            {
                entity.HasComment("商品表");

                entity.Property(e => e.Id).HasComment("主键");

                entity.Property(e => e.Cover).HasMaxLength(255);

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasDefaultValueSql("(getdate())")
                    .HasComment("时间");

                entity.Property(e => e.Name).HasMaxLength(255);

                entity.Property(e => e.Price)
                    .HasColumnType("decimal(18, 2)")
                    .HasDefaultValueSql("((0))");

                entity.Property(e => e.Stock)
                    .HasDefaultValueSql("((0))")
                    .HasComment("库存");

                entity.Property(e => e.UpdateTime).HasColumnType("datetime");
            });

            modelBuilder.Entity<Like>(entity =>
            {
                entity.ToTable("Like");

                entity.Property(e => e.Id)
                    .ValueGeneratedNever()
                    .HasColumnName("id");

                entity.Property(e => e.Aid).HasMaxLength(50);

                entity.Property(e => e.Atitle).HasMaxLength(50);

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("createTime");

                entity.Property(e => e.UpdateTime)
                    .HasColumnType("datetime")
                    .HasColumnName("updateTime");

                entity.Property(e => e.Yn).HasColumnName("YN");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.Createtime).HasColumnType("datetime");

                entity.Property(e => e.Desc).HasMaxLength(50);

                entity.Property(e => e.PassWord)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.Photo)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.UserName)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
